package com.Maykk.Demo03;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @ClassName: ReceiveInputTest
 * @Description: TODO UDP 接收键盘输入的内容
 * @Author: MaykkStar@163.com
 */
public class ReceiveInputTest {
    public static void main(String[] args) throws IOException {
        DatagramSocket ds = new DatagramSocket(9527);
        while (true) {
            byte[] bytes = new byte[1024];
            int length = bytes.length;
            DatagramPacket dp = new DatagramPacket(bytes, length);
            ds.receive(dp);

            byte[] data = dp.getData();
            int dpLength = dp.getLength();
            System.out.println(new String(data, 0, dpLength));

        }
        // 关闭接收，运行不到注释掉
        // ds.close();
    }
}
